
package cn.edu.thu.laud.lasql.index.iface;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;



/**
 * Implements a secondary index for a column family using a second column family
 * in which the row keys are indexed values, and column names are base row keys.
 */
public interface LaUDSecondaryIndex 
{
	/**
	 * delete a column  value of row from index
	 */
	public void deleteColumn(String indexName,ByteBuffer valueKey, ByteBuffer rowKey,ByteBuffer columnName,String columnFamily,String keyspace) throws IOException;
	/**
	 * insert a column  value of row from index
	 */
	public void insertColumn(String indexName,ByteBuffer valueKey, ByteBuffer rowKey,ByteBuffer columnName,String columnFamily,String keyspace) throws IOException;
	/**
	 * update a column  value of row from index
	 */
	public void updateColumn(String indexName,ByteBuffer valueKey, ByteBuffer rowKey,ByteBuffer columnName,String columnFamily,String keyspace) throws IOException ;
/**
 * any thing you want to init the index class.(suggest that do not init parameters in constructor(except static parameters) )
 */
	public void init(String keysapce,String columnFamily,ByteBuffer columnName,String indexName,Map<String, String> options);
	/**
	 * 
	 * validate index Options
	 * @throws ConfigurationException
	 */
	public void validateOptions() throws Exception;


	public void removeIndex(String indexName,ByteBuffer columnName,String columnFamily,String keyspace) throws IOException;
	

/**
 * flush data into disk.
 * @throws IOException
 */
	public void forceBlockingFlush() throws IOException ;
/**
 * get used memory size 
 * @return
 */
	public long getLiveSize();

/**
 * get anything that you save the index files.(File ColumnFamilyStore and so on..) 
 * @return
 */
	public Object getIndexFiles();

	
/**
 * clean the index data but keep the index exist(just clean data ,but do not delete the index.)
 * @param truncatedAt
 */
	public void truncate(long truncatedAt);
	
	
	
	/**
	 * return rowkeys
	 * @param ks
	 * @param cf
	 * @param indexName
	 * @param value
	 * @param reversed 
	 * @param limit . return number
	 * @param optionMap
	 * @return
	 */
	public List<ByteBuffer> search(String ks,String cf,String indexName,ByteBuffer columnName,ByteBuffer  value,boolean reversed,int limit,Map<String,String> optionMap);
	
	/**
	 * check all the parameter is prepared before init.
	 * <br>and write the error into exception's message.
	 * @param optionMap
	 * @throws Exception
	 */
	public void validateOptions(Map<String, String> optionMap) throws Exception;
}
